/**
 * 产品分类列表
 * 文件命名格式：zmn.模块名称.表名称.功能.jas
 * @author duanzuocai
 * @since 2018/11/17
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit', 'laydate'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;

    var cols = [
        [
            {field: 'permitDataId', type: 'checkbox', fixed: 'center',  align: 'center'},
            {field: 'permitDataId', title: 'ID', width: 250, align: 'center', unresize: true, sort: false},
            {
                field: 'type', title: '类型', width: 250, align: 'center', unresize: true, templet: function (d) {
                    return zmnEnum.PERMITDATA_TYPE[d.type];
                }
            },
            {
                field: 'type', title: '类型数据', width: 250, align: 'center', unresize: true, templet: function (d) {
                    var name = "全部";

                    if (d.type == 1 && d.companyName != null) {
                        name = d.companyName;
                    } else if (d.type == 2 && d.serviceName != null) {
                        name = d.serviceName;
                    } else if (d.type == 3 && d.cityName != null) {
                        name = d.cityName;
                    } else if (d.type == 4 && d.channelName != null) {
                        name = d.channelName;
                    } else if ((d.type == 5 || d.type == 6) && d.typeData > 0) {
                        name = zmnEnum.PLAT_TYPE[d.typeData];
                    } else if (d.type == 7 && d.companyName != null) {
                        name = d.companyName;
                    } else if (d.type == 8 && d.companyName != null) {
                        name = d.companyName;
                    } else if ((d.type == 9) && d.typeData > 0) {
                        name= d.companyName;
                    }
                    return name;
                }
            },
            {field: 'deptName', title: '部门', width: 250, align: 'center', unresize: true},
            {field: 'creater', title: '创建人', width: 250, align: 'center', unresize: true},
            {field: 'createTime', title: '创建时间', templet: '#createTime',  align: 'center', unresize: true,
                templet :function (row){
                    return zmnUtil.createTime(row.createTime);
                }
            }
        ]
    ];
    table.render({
        elem: "#zmn-permitdata-table",
        toolbar: "#zmn-permitdata-table-tool",
        title: "权限列表",
        data: json.items,
        limit: json.pageSize,
        cols: cols,
        page: true,
        height: 'full-120'
    });

    laypage.render(zmnPage.laypageOptions(json));

    var ids = new Array();

    // 选择（全选或单选）
    table.on("checkbox(zmn-permitdata-table)", function () {
        ids = zmnPage.layIdsChecked(json.items, "permitDataId");
    });

    // 删除
    table.on("toolbar(zmn-permitdata-table)", function (obj) {
        if (obj.event != "del") {
            return;
        }
        if (ids.length === 0) {
            return layer.alert("请选择至少一条数据！");
        }
        zmnPage.layStartStop(obj, "/mc/permit/data/del.action", ids.join(","));
    });

    // 修改排序
    table.on("edit(zmn-permitdata-table)", function (obj) {
        zmnPage.laySort(obj, "/mc/permit/data/updateSort.action", obj.data.categId);
    });

    //对外暴露的接口
    exports('art_permitdata_list', {});
});

function toEditPermit(){
    let deptId = json.deptId;
    layer.open({
        type: 2,
        title:'权限管理',
        area: ['90%', '80%'],
        content: '/mc/permit/data/detail.action?deptId='+deptId
    });

}

function reload(msg){
    parent.layui.layer.msg(msg);
    window.location.reload();
}